package com.neusoft.ruangong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neusoft.ruangong.domain.User;
import com.neusoft.ruangong.mapper.UserMapper;
import com.neusoft.ruangong.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigInteger;
import java.util.List;

;

/**
 * @author zhanglei
 * @create: 2021/06/29/12:47
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User goLogin(String name, String password,Integer role) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("name", name);
        wrapper.eq("password", password);
        wrapper.eq("role", role);

        wrapper.select("name","password","role");
        List<User> users = userMapper.selectList(wrapper);
        if (users.size()!=0) {
            log.info("...登录成功" + users.get(0));
            return users.get(0);
        }
        log.info("...登录失败");
        return null;
    }

    @Override
    public BigInteger queryByName(String name) {
        return userMapper.selectByName(name);
    }

    @Override
    public Long queryByNameLong(String name) {
        return userMapper.queryByNameLong(name);
    }

    @Override
    public User queryUserByName(String name) {
        return userMapper.queryUserByName(name);
    }

}
